<?php 

// 控制基类 继承smarty模板
class Controller extends Smarty
{
    // 实例化继承smarty的子类时 就会自动触发
    public function __construct()
    {
        // smarty的初始化配置
        $this->setTemplateDir('./views')
                ->setCompileDir('./runtime/views_c')
                ->setConfigDir('./configs')
                ->setCacheDir('./runtime/caches');

        // 配置模板变量的定界符
        $this->left_delimiter = LEFT_D;
        $this->right_delimiter = RIGHT_D;

        // 配置缓存 缓存时间
        $this->caching = CACHING;
        $this->cache_lifetime = CACHE_LIFETIME;

    }

    // 跳转重定向的功能
    public function redirect($message, $url=null)
    {
        echo "<script>alert('{$message}')</script>";
        if (empty($url)) {
            echo "<script>history.back()</script>";
        } else {
            echo "<script>location.href='{$url}'</script>";
        }
        
    }


    // __call访问不存在的方法时自动触发 两个参数
    public function __call($fun,$params)
    {
        header("HTTP/1.0 404 not found");
        echo "<h1>404 NOT FOUND  方法不存在</h1>";
        exit;
    }

}
 ?>